package com.firmboy.schedu.hello.task;

import com.firmboy.schedu.dao.RediaDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 定时任务
 *
 * @author firmboy
 * @create 2018-03-14 上午9:19
 **/
@Component
public class ScheduTask {

    private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    @Autowired
    private RediaDao rediaDao;

    @Scheduled(cron = "5,15,25,35,45,55 * * * * ?")
    public void task1() throws InterruptedException {
        boolean lock = rediaDao.getLock("task1-lock");
        if(lock){
            System.out.println("我是8082啊");
            System.out.println("现在的时间是："+format.format(new Date()));
            Thread.sleep(2000L);
            rediaDao.releaseLock("task1-lock");
        }
    }
}
